Skip to content

Comments

fix(parallel): correct active state pulsing and duration display for parallel subflow blocks#3305

Merged
waleedlatif1 merged 5 commits intostagingfrom
active-exec
Feb 22, 2026
Merged

fix(parallel): correct active state pulsing and duration display for parallel subflow blocks#3305
waleedlatif1 merged 5 commits intostagingfrom
active-exec

Conversation

@waleedlatif1
Copy link
Collaborator

Summary

  • Fix child blocks inside parallel subflows not showing the pulsing active state animation during execution — executor now emits the base block ID (via node.metadata.originalBlockId) instead of the branch-suffixed ID, and ref counting ensures the block stays active until all branches complete
  • Fix parallel container showing summed branch durations (e.g. 10s for 5×2s branches) instead of wall-clock time (~2s) — terminal now uses max(endedAt) - min(startedAt) for parallel subflow and iteration nodes; loop subflows retain the serial sum

Type of Change

  • Bug fix

Testing

Tested manually

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

@vercel
Copy link

vercel bot commented Feb 22, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Skipped Skipped Feb 22, 2026 11:03pm

Request Review

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Feb 22, 2026

Greptile Summary

This PR fixes two visual bugs with parallel subflow blocks during workflow execution:

  • Active state pulsing: The executor now emits the base block ID (via node.metadata.originalBlockId) instead of the branch-suffixed internal ID, so the UI can correctly match block events to canvas blocks. A ref-counting mechanism ensures a block stays visually active until all parallel branches complete.
  • Duration display: The terminal now uses wall-clock time (max(endedAt) - min(startedAt)) for parallel subflow and iteration nodes, instead of incorrectly summing individual branch durations. Loop subflows correctly retain the serial sum.

Key observations:

  • The originalBlockId field was already set on all parallel branch nodes during DAG construction (nodes.ts:111) and expansion (parallel-expansion.ts:125), so the fallback ?? node.id safely handles non-parallel nodes.
  • The ref-counting logic is duplicated between use-workflow-execution.ts (via buildBlockEventHandlers) and workflow-execution-utils.ts (direct SSE processing for copilot tools). Both paths are consistent but could benefit from a shared helper to prevent future drift.

Confidence Score: 4/5

  • This PR is safe to merge — it fixes targeted UI bugs with a well-understood mechanism (ref counting + ID remapping) and no behavioral changes to execution logic.
  • The changes are logically sound and well-scoped. The originalBlockId fallback pattern is safe because the field is already populated during DAG construction. The ref-counting logic is straightforward and consistent across both code paths. Score is 4 rather than 5 due to lack of automated tests and duplicated ref-counting logic that could drift.
  • Pay attention to workflow-execution-utils.ts — its ref-counting logic duplicates use-workflow-execution.ts and could diverge in future changes.

Important Files Changed

Filename Overview
apps/sim/executor/execution/block-executor.ts Uses node.metadata?.originalBlockId ?? node.id in callOnBlockStart and callOnBlockComplete so the executor emits the base block ID for UI events instead of branch-suffixed IDs. Correct and well-targeted change.
apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/terminal/utils.ts Introduces wall-clock duration (max(endedAt) - min(startedAt)) for parallel subflows/iterations, preserving serial sum for loop iterations. Logic is correct and well-commented.
apps/sim/app/workspace/[workspaceId]/w/[workflowId]/hooks/use-workflow-execution.ts Adds activeBlockRefCounts Map for ref-counting active blocks across parallel branches. The updateActiveBlocks function correctly increments/decrements. Ref count map is threaded through all 4 call sites of buildBlockEventHandlers.
apps/sim/app/workspace/[workspaceId]/w/[workflowId]/utils/workflow-execution-utils.ts Adds identical ref-counting logic for active blocks in the separate SSE event processing path (used by copilot tools). Logic duplicates the pattern in use-workflow-execution.ts but is consistent.

Sequence Diagram

sequenceDiagram
    participant Executor as BlockExecutor
    participant SSE as SSE Stream
    participant Hook as useWorkflowExecution
    participant RefCount as activeBlockRefCounts
    participant UI as Canvas UI

    Note over Executor: Parallel block A runs in 3 branches<br/>(A__branch-0, A__branch-1, A__branch-2)

    Executor->>SSE: block:started (blockId: A)<br/>via originalBlockId
    SSE->>Hook: event block:started A
    Hook->>RefCount: refCount[A] = 0 → 1
    Hook->>UI: activeBlocks.add(A) → pulse ON

    Executor->>SSE: block:started (blockId: A)
    SSE->>Hook: event block:started A
    Hook->>RefCount: refCount[A] = 1 → 2

    Executor->>SSE: block:started (blockId: A)
    SSE->>Hook: event block:started A
    Hook->>RefCount: refCount[A] = 2 → 3

    Executor->>SSE: block:completed (blockId: A)
    SSE->>Hook: event block:completed A
    Hook->>RefCount: refCount[A] = 3 → 2
    Note over UI: Still pulsing (count > 0)

    Executor->>SSE: block:completed (blockId: A)
    SSE->>Hook: event block:completed A
    Hook->>RefCount: refCount[A] = 2 → 1

    Executor->>SSE: block:completed (blockId: A)
    SSE->>Hook: event block:completed A
    Hook->>RefCount: refCount[A] = 1 → 0
    Hook->>UI: activeBlocks.delete(A) → pulse OFF
Loading

Last reviewed commit: 04fbe1d

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

4 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

@waleedlatif1
Copy link
Collaborator Author

Addressed in 6b407ee — extracted updateActiveBlockRefCount into workflow-execution-utils.ts as a shared export. Both workflow-execution-utils.ts and use-workflow-execution.ts now call the same function.

@waleedlatif1
Copy link
Collaborator Author

@cursor review

@waleedlatif1
Copy link
Collaborator Author

@cursor review

…h success masking failure"

This reverts commit 9c087cd.
@waleedlatif1 waleedlatif1 merged commit 687c125 into staging Feb 22, 2026
3 checks passed
@waleedlatif1 waleedlatif1 deleted the active-exec branch February 22, 2026 23:03
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant